package me.luger.project.fof.controller.admin;

import me.luger.core.dao.nutz.entity.page.DataTableRequest;
import me.luger.core.mvc.controller.BaseController;
import me.luger.core.mvc.entity.Result;
import me.luger.core.mvc.interceptor.oplog.OpLog;
import me.luger.project.fof.service.AssetStrategyInfoService;
import me.luger.project.fof.service.BenchmarkService;
import me.luger.project.fof.entity.AssetStrategyInfo;
import me.luger.project.fof.entity.Benchmark;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * AssetStrategyInfo controller
 */
@Controller
@RequestMapping("/private/fof/assetStrategyInfo")
public class AssetStrategyInfoController extends BaseController {

    private String viewBasePath = "/admin/modules/assetStrategyInfo/";

    @Autowired
    private AssetStrategyInfoService assetStrategyInfoService;

    @Autowired
    private BenchmarkService benchmarkService;

    @RequestMapping(value = "",name = "AssetStrategyInfo列表页面")
    public ModelAndView index(){
        return btlView(viewBasePath + "index");
    }

    @RequestMapping(value = "data",name = "获取AssetStrategyInfo列表")
    @ResponseBody
    public Object data(@RequestBody final DataTableRequest dataTableRequest){
        Sql sql = Sqls.create("select a.*,b.name as benchmarkName from fof_asset_strategy_info a left join fof_benchmark b on a.benchmarkId = b.id $condition");
        return assetStrategyInfoService.data(dataTableRequest,sql);
    }



    @RequestMapping(value = "delete",name = "删除AssetStrategyInfo接口")
    @ResponseBody
    public Object delete(String[] ids){
        assetStrategyInfoService.delete(ids);
        return Result.success("delete success");
    }

    @RequestMapping(value = "/detail/{id}",name = "获取AssetStrategyInfo详细信息接口")
    public ModelAndView detail(@PathVariable("id") Integer id){
        AssetStrategyInfo assetStrategyInfo = assetStrategyInfoService.fetchById(id);
        setAttr("assetStrategyInfo",assetStrategyInfo);
        return btlView(viewBasePath + "detail");
    }

    @RequestMapping(value = "add",name = "添加AssetStrategyInfo页面")
    public ModelAndView add(){
        List<Benchmark> benchmarkList = benchmarkService.getAllBenchMark();
        setAttr("benchmarkList",benchmarkList);
        return btlView(viewBasePath + "add");
    }

    @RequestMapping(value = "addDo",name = "添加AssetStrategyInfo接口")
    @ResponseBody
    @OpLog(name = "添加AssetStrategyInfo",msg = "添加AssetStrategyInfo}")
    public Object adddo(AssetStrategyInfo assetStrategyInfo){
        try{
            assetStrategyInfo = assetStrategyInfoService.insert(assetStrategyInfo);
        }catch (Exception e){
            return Result.error();
        }
        return Result.success();
    }

    @RequestMapping(value = "/edit/{id}",name = "更新AssetStrategyInfo信息页面")
    public ModelAndView edit(@PathVariable Integer id){
        AssetStrategyInfo assetStrategyInfo = assetStrategyInfoService.fetchById(id);
        setAttr("assetStrategyInfo",assetStrategyInfo);

        List<Benchmark> benchmarkList = benchmarkService.getAllBenchMark();
        setAttr("benchmarkList",benchmarkList);
        return btlView(viewBasePath + "edit");
    }

    @RequestMapping(value = "editDo",name = "更新AssetStrategyInfo接口")
    @ResponseBody
    public Object editDo(AssetStrategyInfo assetStrategyInfo){
        try{
            assetStrategyInfoService.updateIgnoreNull(assetStrategyInfo);
        }catch (Exception e){
            return Result.error();
        }
        return Result.success();
    }
}
